package com.north.light.libpicselect.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.north.light.libpicselect.R;


public class LibPicToastUtils {
    private static Toast mToast;

    //自定义short toast
    //change by lzt 20210916 修改多次toast失效问题
    public static void toast(Context context, String word, int Length) {
        LayoutInflater inflater = (LayoutInflater) context.getApplicationContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.lib_pic_view_toast, null);
        TextView text = (TextView) view.findViewById(R.id.view_base_toast_tx);
        text.setText(word);
        if (mToast == null) {
            mToast = new Toast(context.getApplicationContext());
        } else {
            mToast.cancel();
            mToast = new Toast(context.getApplicationContext());
        }
        mToast.setView(view);
        if (mToast.getView() != null) {
            mToast.getView().setBackgroundResource(R.drawable.lib_pic_shape_view_toast_bg);
        }
        mToast.setGravity(Gravity.BOTTOM, 0,
                context.getApplicationContext().getResources().getDisplayMetrics().heightPixels / 10);
        mToast.setDuration(Length);
        mToast.show();
    }
}
